package com.zxt.service.impl;

import com.zxt.dao.CarDao;
import com.zxt.dao.impl.CartDaoImpl;
import com.zxt.domain.Cart;
import com.zxt.domain.Goods;
import com.zxt.service.CartService;
import com.zxt.service.GoodsService;

import java.util.List;

public class CartServiceImpl implements CartService {
    private CarDao carDao=new CartDaoImpl();
    @Override
    public void add(Cart cart) {
      carDao.insert(cart);
    }

    @Override
    public Cart find(Integer uid, Integer goods_id) {
        return carDao.select(uid,goods_id);
    }

    @Override
    public void modfiy(Cart cart) {
      carDao.update(cart);
    }

    @Override
    public List<Cart> find(Integer uid) {
        List<Cart> cartList = carDao.select(uid);
        if (cartList != null&&cartList.size()>0){
            GoodsService goodsService=new GoodsServiceImpl();
            for (Cart cart: cartList){
                Goods goods = goodsService.findById(cart.getPid());
                cart.setGoods(goods);
            }
        }
        return cartList;
    }

    @Override
    public void remove(Integer uid, int goods_id) {
         carDao.delete(uid,goods_id);
    }

    @Override
    public void clear(Integer uid) {
        carDao.delete(uid);
    }
}
